import 'package:flutter/material.dart';
import '../../model/post.dart';

class CardDemo extends StatefulWidget {
  CardDemo({Key key}) : super(key: key);

  @override
  _CardDemoState createState() => _CardDemoState();
}

class _CardDemoState extends State<CardDemo> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("CardDemo"),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(16.0),
        child: ListView(
          children: posts.map(
            (post) => Card(
              child: Column(
                children: [
                  AspectRatio(
                    aspectRatio: 16/9,
                    child: ClipRRect( // 添加图片圆角效果
                      child: Image(
                        image: AssetImage(post.imageUrl), 
                        fit: BoxFit.cover,
                      ),
                      borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(6.0),
                        topRight: Radius.circular(6.0),
                      ),
                    ),
                  ),
                  ListTile(
                    leading: CircleAvatar(
                      backgroundImage: AssetImage('assets/images/avatar.png'),
                    ),
                    title: Text(post.title),
                    subtitle: Text(post.author),
                  ),
                  Container( // 设置描述性文字及样式
                    padding: EdgeInsets.all(16.0),
                    child: Text(
                      "说明性描述文字,说明性描述文字,说明性描述文字,说明性描述文字,说明性描述文字,说明性描述文字,说明性描述文字,说明性描述文字,说明性描述文字,说明性描述文字",
                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ),
                  ButtonBar(
                    children: [
                      FlatButton(onPressed: () {}, child: Text("分享 250")),
                      FlatButton(onPressed: () {}, child: Text("转发 100"))
                    ],
                  ),
                ],
              ),
            ),
          ).toList(),
        ),
      ),
    );
  }
}